package org.xxf.tdengine.demo.netty;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;

/**
 * @Author: hxq
 * @Date: 2020/8/10 9:48
 */
public class SecureUtils {

    private final static byte[] KEY= "awa456789abcdefa".getBytes();
    private final static byte[] IV = "0102030405123456".getBytes();

    /**
     * aes解密
     * @param content
     * @return
     */
    public static String AESDecryp(String content){
        // 构建
        AES aes = new AES(Mode.CBC, Padding.ZeroPadding, KEY, IV);
        // 加密为16进制表示
        String encryptHex = aes.encryptBase64(content);
//        String encryptHex = aes.encryptHex(content);
        // 解密为字符串
        String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
//        System.out.print("加密后的数据:"+encryptHex);
//        System.err.printf("解密为字符串:"+decryptStr);
        return encryptHex;
    }

    public static void main(String[] args) {
//        AESDecryp("WMZS*9f4cc593d4a659e9");
////        AESDecryp("abcdefgh12345678");

//        Date a = DateUtil.parseDateTime(String.valueOf(DateUtil.parse("server*192.168.0.25")));
//        System.out.printf("a"+a);

        System.out.println(SecureUtils.AESDecryp("xuxiangfeng"));

    }

}